<template>
	<view class="container">
		<!-- 内容区域包装器 -->
		<view class="content-wrapper">
			<!-- 搜索区域 -->
			<view class="search-box">
				<u-search placeholder="请输入关键搜索" v-model="formData.kw" :show-action="false" :clearabled="true"
					:animation="false" shape="round" bgColor="#F5F6FA" height="72rpx" searchIconColor="#999999"
					placeholderColor="#999999" @change="changekeword" :inputStyle="{
						color: '#333333',
						backgroundColor: '#F5F6FA',
					}"></u-search>
				<view class="add-btn" @click="handleToAdd">
					<u-icon name="plus-circle" size="40rpx" color="#FE4F04"></u-icon>
				</view>
			</view>
		</view>
		<view class="content-box">
			<view class="empty-review" v-if="list.length == 0">
				<image src='../static/images/empty-review.png' mode="aspectFit"></image>
			</view>
			<view class="content-list">
				 <!-- @click="handleToDetail(item.id)" -->
				<view class="content-item" v-for="item in list" :key="item.id">
					<view class="content-item-top">
						<view class="content-item-title">
							<u-icon name="bell-fill" color="#FE4F04" size="30rpx"></u-icon>
							{{item.title}}
						</view>
						<view class="content-item-date"> {{item.create_time_text}} </view>
					</view>
					<view class="content-item-text">
						<rich-text :nodes="item.content"></rich-text>
					</view>
					<view class="content-item-opt">
						<u-button :custom-style="customStylePreview" @click="handleToPreview(item)">预览</u-button>
						<u-button :custom-style="customStyleSend" @click="handleSend(item)">发送</u-button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>


<script>
	import { getNoticeIndex, noticeSend } from "@/api/part2.js";
	export default {
		data() {
			return {
				formData: {
					page: 1,
					page_size: 10,
					kw: ''
				},
				total: 0,
				list: [	],
				customStylePreview: {
					width: '152rpx',
					height: '64rpx',
					fontSize: '26rpx',
					color: '#FE4F04',
					borderRadius: '44rpx',
					border: '2rpx solid #FE4F04',
					margin:'0'
				},
				customStyleSend: {
					width: '152rpx',
					height: '64rpx',
					fontSize: '26rpx',
					color: '#FFFFFF',
					borderRadius: '44rpx',
					background: '#FE4F04',
					margin:'0'
				},
				timerId:null
			};
		},
		onShow() {
			this.handleFilter()
		},
		async onReachBottom() {
			if(this.list.length < this.total) {
				this.formData.page++
				this.init()
			}
		},
		methods: {
			changekeword() {
				if(this.timerId) {
					clearInterval(this.timerId)
				}
				let that = this
				this.timerId = setTimeout(()=>{
					that.handleFilter()
				},200)
			},
			handleFilter(){
				this.formData.page = 1
				this.list = []
				this.init()
			},
			init() {
				getNoticeIndex(this.formData).then(res => {
					console.log(res.data);
					res.data.data.data.forEach((item) => {
						this.list.push(item)
					})
					this.total = res.data.data.total
				})
			},
			handleToAdd(){
				uni.navigateTo({
					url:'/pages-landlord/announcement/detail'
				})
			},
			handleSend(item) {
				noticeSend({id:item.id}).then(res=>{
					uni.$u.toast(res.msg || '发送成功')
				})
			},
			handleToPreview(item){
				console.log(item)
				uni.navigateTo({
					url:'/pages-landlord/announcement/preview?id='+item.id+"&title="+item.title
				})
			}
			// handleToDetail(id){
			// 	console.log(id)
			// 	uni.navigateTo({
			// 		url:'/pages-landlord/announcement/detail?id='+id
			// 	})
			// }
		},
	};
</script>

<style lang="less" scoped>
	.search-box {
		padding: 12rpx 20rpx 24rpx 32rpx;
		background-color: #fff;
		display: flex;
	}

	.add-btn {
		padding: 20rpx;
	}

	.content-box {
		padding: 24rpx 32rpx;
	}

	.content-total {
		padding: 16rpx 0;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 22rpx;
		color: #999999;
	}

	.content-item {
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(0, 0, 0, 0.01);
		border-radius: 24rpx;
		padding: 24rpx;
		margin-bottom: 24rpx;
	}

	.content-item-top {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.content-item-title {
		font-family: PingFangHK, PingFangHK;
		font-weight: 500;
		font-size: 30rpx;
		color: #222222;
		line-height: 42rpx;
		display: flex;
	}

	.content-item-date {
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		line-height: 34rpx;
	}

	.content-item-text {
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #585858;
		line-height: 40rpx;
		padding: 20rpx 0;

		display: -webkit-box;
		/* 必须使用 flex 布局 */
		-webkit-box-orient: vertical;
		/* 垂直方向 */
		-webkit-line-clamp: 3;
		/* 限制显示行数 */
		overflow: hidden;
		/* 超出部分隐藏 */
		text-overflow: ellipsis;
		/* 超出部分显示省略号 */
	}

	.content-item-opt {
		display: flex;
		gap: 24rpx;
		justify-content: flex-end;
	}
	.empty-review {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 48rpx 0;
	
		image {
			width: 328rpx;
			height: 208rpx;
			margin-bottom: 24rpx;
		}
	}
</style>